import grails.util.GrailsUtil
import apralms.*

class BootStrap {

	def init = { servletContext ->
		switch(GrailsUtil.environment){
			case "development":
			
				def admin = new User(login:"admin", password:"admin", role:"管理员")
				admin.save()
				if(admin.hasErrors()){
					println admin.errors
				}
				def jdoe = new User(login:"jdoe", password:"jdoe",role:"普通用户")
				jdoe.save()
				if(jdoe.hasErrors()){
					println jdoe.errors
				}

//				def p1 = new Project(
//					code:"P01",
//					name:"Project-01",
//					birthDate: new Date()
//				)
//				p1.save()
//				if(p1.hasErrors()){
//					println p1.errors
//				}
//
//				def s1 = new System(
//					code:"S01",
//					name:"System-01",
//					project:p1
//				)
//				s1.save()
//				if(s1.hasErrors()){
//					println s1.errors
//				}
		}
	}

	def destroy = {
		switch(GrailsUtil.environment){
			case "development":
			
				def s1 = System.getByCode("S01")
				s1.delete()
				
				def p1 = Project.getByCode("P01")
				p1.delete()
		}
	}
}
